package top.yaofengqiao.springcloudsimple.auth.biz.domain.auth.service.impl;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import top.yaofengqiao.springcloudsimple.auth.biz.domain.auth.model.entity.RoleEntity;
import top.yaofengqiao.springcloudsimple.auth.biz.domain.auth.repository.IRoleRepository;
import top.yaofengqiao.springcloudsimple.auth.biz.domain.auth.service.IPermissionService;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yfq
 * @date 2024/6/4 16:00
 * @description
 */
@Service
public class PermissionService implements IPermissionService {
    @Resource
    private IRoleRepository roleRepository;

    @Override
    public List<String> queryRoles(long userId) {
        List<RoleEntity> roleEntities = roleRepository.queryByUserId(userId);

        if (CollUtil.isEmpty(roleEntities)) return Collections.emptyList();

        return roleEntities.stream().map(RoleEntity::getCode).collect(Collectors.toList());
    }

}
